var express = require('express');
const multer = require("multer")
const path = require("path")
var router = express.Router();
var User = require('../controllers/UserController')

var storage = multer.diskStorage({
	// 配置文件上传后存储的路径
	destination: function(req, file, cb) {
		// NodeJS的两个全局变量
		// console.log(__dirname); //获取当前文件在服务器上的完整目录 
		// console.log(__filename); //获取当前文件在服务器上的完整路径 
		cb(null, path.join(__dirname, '../public/uploads'))
	},
	// 配置文件上传后存储的路径和文件名
	filename: function(req, file, cb) {
		// console.log('file', file);
		cb(null, Date.now() + path.extname(file.originalname))
	}
})
var upload = multer({
	storage: storage
})

/* GET users listing. */
router.post('/emailsendCode', User.emailsendCode);
router.post('/registered', User.registered);
router.post('/signuser', User.signuser);
router.get('/deleteid', User.deleteid);
router.post('/modifyuserpass', User.modifyuserpass);
router.get('/userinfo', User.userinfo);
router.get('/userarticlelist', User.userarticlelist);
router.get('/usercatelist', User.usercatelist);
router.get('/userarticledis', User.userarticledis);
router.get('/userproject', User.userproject);
router.get('/userdis', User.userdis);
router.get('/catearticle', User.catearticle);
router.get('/getabout', User.getabout);
router.post('/addoreditdiscuss', User.addoreditdiscuss);
router.post('/addoreditreply', User.addoreditreply);
router.post('/addoreditproject', User.addoreditproject);
router.post('/addoreditcate', User.addoreditcate);
router.post('/addoreditarticle', User.addoreditarticle);
router.post('/addoredituser', User.addoredituser);
router.get('/adminwpynum', User.adminwpynum);
router.post("/addUpload", upload.single("file"), User.addUpload)

module.exports = router;
